﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ShevaEngine.Core.Modules.Renderer
{
    /// <summary>
    /// Draw call key.
    /// </summary>
    public class DrawCallKey
    {
        /// <summary>ID.</summary>
        public UInt64 ID;

        /// <summary>Material Id.</summary>
        public UInt16 MaterialID;
        /// <summary>Texture state.</summary>
        public UInt16 TextureState;
        /// <summary>Material parameters ID..</summary>
        public UInt16 MaterialParamsID;
        /// <summary>Buffers ID.</summary>
        public UInt16 BuffersID;

        /// <summary>
        /// Konstruktor.
        /// </summary>
        public DrawCallKey(UInt16 materialID, UInt16 textureState, UInt16 materialParamsID, UInt16 buffersID)
        {
            this.MaterialID = materialID;
            this.TextureState = textureState;
            this.MaterialParamsID = materialParamsID;
            this.BuffersID = buffersID;

            //this.ID = 
        }
    }

    /// <summary>
    /// Draw call key comparer.
    /// </summary>
    public class DrawCallKeyComparer : IComparer<DrawCallKey>
    {
        /// <summary>
        /// Compare method.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public int Compare(DrawCallKey x, DrawCallKey y)
        {
            int diff = x.MaterialID - y.MaterialID;

            if (diff == 0)
            {
                diff = x.TextureState - y.TextureState;

                if (diff == 0)
                {
                    diff = x.MaterialParamsID - y.MaterialParamsID;

                    if (diff == 0)
                    {
                        return Math.Sign(x.BuffersID - y.BuffersID);
                    }
                    else
                        return Math.Sign(diff);
                }
                else
                    return Math.Sign(diff);
            }
            else
                return Math.Sign(diff);
        }
    }
}
